//
//  ViewController.m
//  02_Homework
//
//  Created by 徐昊 on 16/7/15.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "ViewController.h"
#import "ImgTextFieldView.h"
#import "VCOfRegister.h"
#import "VCOfFoundPassword.h"
#define WIDTH self.view.bounds.size.width
@interface ViewController ()<UITextFieldDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self config];
    self.navigationController.navigationBar.hidden = YES;
    
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)config {
    self.view.backgroundColor = [UIColor whiteColor];
    UIImageView *backImage = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    /** 背景图 */
    [backImage setImage:[UIImage imageNamed:@"welcome_2"]];
    [self.view addSubview:backImage];
    /** 拉钩图标 */
    UIImageView *photoView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH / 2 - 65, 70, 130, 130 * 296 / 184)];
    [photoView setImage:[UIImage imageNamed:@"logo_lagou"]];
    [backImage addSubview:photoView];
    
    /** 账号输入 */
    ImgTextFieldView *accout = [[ImgTextFieldView alloc] initWithFrame:CGRectMake(15, 300, WIDTH - 30, 50) image:[UIImage imageNamed:@"icon_username"] placeHolder:@"请输入用户名或手机号"];
    [self.view addSubview:accout];
    accout.textField.delegate = self;
    accout.textField.tag = 1;
    accout.imageView.tag = 10;
    
    /** 贝塞尔曲线做圆角 */
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:accout.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = accout.bounds;
    maskLayer.path = maskPath.CGPath;
    accout.layer.mask = maskLayer;
    
    /** 密码输入 */
    ImgTextFieldView *passWord = [[ImgTextFieldView alloc] initWithFrame:CGRectMake(15, 352, WIDTH - 30, 50) image:[UIImage imageNamed:@"icon_password"] placeHolder:@"请输入密码"];
    [self.view addSubview:passWord];
    passWord.textField.delegate = self;
    passWord.textField.tag = 2;
    passWord.imageView.tag = 20;
    
    /** 贝塞尔曲线做圆角 */
    UIBezierPath *passwordMaskPath = [UIBezierPath bezierPathWithRoundedRect:passWord.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *passwordMaskLayer = [[CAShapeLayer alloc] init];
    passwordMaskLayer.frame = passWord.bounds;
    passwordMaskLayer.path = passwordMaskPath.CGPath;
    passWord.layer.mask = passwordMaskLayer;
    
    
    /** 登录按钮 */
    UIButton *logIn = [UIButton buttonWithType:UIButtonTypeSystem];
    logIn.frame = CGRectMake( 15, 430, WIDTH - 30, 50);
    logIn.backgroundColor = [UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00];
    [logIn setTitle:@"登录" forState:UIControlStateNormal];
    [logIn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [logIn addTarget:self action:@selector(logIn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:logIn];
    [logIn.layer setCornerRadius:10.0];
    
    
    /** 忘记密码 */
    UIButton *forgetPassword = [UIButton buttonWithType:UIButtonTypeSystem];
    forgetPassword.frame = CGRectMake(15, 500, 100, 40);
    [forgetPassword setTitle:@"忘记密码" forState:UIControlStateNormal];
    [forgetPassword setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    forgetPassword.titleLabel.font = [UIFont systemFontOfSize:20];
    [self.view addSubview:forgetPassword];
    [forgetPassword addTarget:self action:@selector(foundPassword) forControlEvents:UIControlEventTouchUpInside];
    
    /** 注册 */
    UIButton *regist = [[UIButton alloc] initWithFrame:CGRectMake(130, 560, WIDTH - 260, 40)];
    [regist setTitle:@"现在注册拉钩" forState:UIControlStateNormal];
    [regist setTitleColor:[UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00] forState:UIControlStateNormal];
    regist.titleLabel.font = [UIFont systemFontOfSize:22 weight:15];
    [self.view addSubview:regist];
    [regist addTarget:self action:@selector(presentVC:) forControlEvents:UIControlEventTouchUpInside];
    
    
    /** 下面的-- or -- */
    UIView *leftLine = [[UIView alloc] initWithFrame:CGRectMake(15, 620, WIDTH / 2 - 35, 1)];
    leftLine.backgroundColor = [UIColor whiteColor];
    [backImage addSubview:leftLine];
        UIView *rightLine = [[UIView alloc] initWithFrame:CGRectMake(WIDTH / 2 + 20, 620, WIDTH / 2 - 35, 1)];
    rightLine.backgroundColor = [UIColor whiteColor];
    [backImage addSubview:rightLine];
    UILabel *or = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 2 - 20, 610, 40 , 20)];
    or.text = @"or";
    [backImage addSubview:or];
    or.textAlignment = NSTextAlignmentCenter;
    or.textColor = [UIColor whiteColor];
    or.font = [UIFont systemFontOfSize:25 weight:0.5];
    
    /** 随便逛逛 */
    UIButton *other = [[UIButton alloc] initWithFrame:CGRectMake(WIDTH / 2 - 50, 650, 100, 30)];
    [other setTitle:@"随便逛逛 >" forState:UIControlStateNormal];
    [other setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:other];
    
}

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    if (textField.tag == 1) {
        UIImageView *i = [self.view viewWithTag:10];
        [i setImage:[UIImage imageNamed:@"icon_username_select"]];
    }
    if (textField.tag == 2) {
        UIImageView *i = [self.view viewWithTag:20];
        [i setImage:[UIImage imageNamed:@"icon_password_select"]];
    }
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    if (textField.tag == 1) {
        UIImageView *i = [self.view viewWithTag:10];
        [i setImage:[UIImage imageNamed:@"icon_username"]];
    }
    if (textField.tag == 2) {
        UIImageView *i = [self.view viewWithTag:20];
        [i setImage:[UIImage imageNamed:@"icon_password"]];
    }
}

/** 点击回车收回键盘 */
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField endEditing:YES];
    return YES;
}

/** 点击屏幕收回键盘 */
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

// navigationController push推出下个界面
/** 模态推出 */
- (void)presentVC:(UIButton *)button {
    VCOfRegister *regist = [[VCOfRegister alloc] init];
    [self.navigationController pushViewController:regist animated:YES];
//    regist.modalTransitionStyle = UIModalTransitionStylePartialCurl;
//    [self presentViewController:regist animated:YES completion:^{
//        
//        
//    }];
}

- (void)foundPassword {
    VCOfFoundPassword * foundPassword = [[VCOfFoundPassword alloc] init];
    [self.navigationController pushViewController:foundPassword animated:YES];
//    [self presentViewController:foundPassword animated:YES completion:^{
//        
//        
//    }];
}

/** 登录按钮动作 */
- (void)logIn {
    NSLog(@"没实现, 别点了!");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
